<template>
  <el-drawer v-model="drawerVisible" title="搜索" direction="rtl" size="350px">
    <template #header>
      <span class="text-16px font-700">搜索</span>
    </template>
    <div class="search-drawer" style="height: 100%">
      <el-form
        ref="queryFormRef"
        :inline="true"
        :model="queryParams"
        class="-mb-15px"
        label-width="68px"
      >
        <el-form-item label="高度代码" prop="heiCheightcd">
          <el-input
            v-model="queryParams.heiCheightcd"
            placeholder="请输入高度代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="英文名称" prop="heiName">
          <el-input
            v-model="queryParams.heiName"
            placeholder="请输入英文名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="中文名称" prop="heiCmeaning">
          <el-input
            v-model="queryParams.heiCmeaning"
            placeholder="请输入中文名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="有效标志" prop="heiIsvalid">
          <el-radio-group v-model="queryParams.heiIsvalid">
            <el-radio
              v-for="dict in getStrDictOptions(DICT_TYPE.VALID_SIGN)"
              :key="dict.value"
              :label="dict.value"
            >
              {{dict.label}}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="高箱标志" prop="heiIshigh">
          <el-radio-group v-model="queryParams.heiIshigh">
            <el-radio
              v-for="dict in getStrDictOptions(DICT_TYPE.HC_SIGN)"
              :key="dict.value"
              :label="dict.value"
            >
              {{dict.label}}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="heiRemark">
          <el-input
            v-model="queryParams.heiRemark"
            placeholder="请输入备注"
            clearable
            class="!w-240px"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div style="flex: auto">
        <el-button @click="reset">重置</el-button>
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
  import {DICT_TYPE, getStrDictOptions} from '@/utils/dict'

  // 定义 props 和 emits
  const props = defineProps({
    modelValue: {
      type: Object,
      required: true,
    }
  });

  const emit = defineEmits(['update:modelValue', 'search', 'reset']);

  // 控制抽屉显示
  const drawerVisible = ref(false);

  // 使用 computed 实现双向绑定
  const queryParams = computed({
    get: () => props.modelValue,
    set: (value) => emit('update:modelValue', value)
  });

  // 打开抽屉
  function open() {
    drawerVisible.value = true;
  }

  // 关闭抽屉
  function close() {
    drawerVisible.value = false;
  }

  // 搜索
  function search() {
    close();
    emit('search', queryParams.value);
  }

  const queryFormRef = ref()
  // 重置
  function reset() {
    queryFormRef.value.resetFields()
    emit('reset', queryParams.value);
  }

  // 暴露 open 方法
  defineExpose({
    open
  });
</script>

<style lang="scss" scoped>
  .search-drawer {
    ::v-deep {
      .el-form {
        height: 98%;
      }
    }
  }
</style>
